
async function sleep(ms) {
	return new Promise((resolve, reject) => {
		setTimeout(()=> {
			resolve(Math.random())
		}, ms)
	})
}



/* // 这里不知道怎么串联起来了  2021年3月27日15:46:44 todo
console.time('sleep2')

var i = 0 , total = 0;
var promise = Promise.resolve()
while(i < 10) {
	promise  = promise.then(() => {
		total += i * 200
		console.log('i = ', i)
		return i < 10 ? sleep(i++ * 200) : i
	});

}
console.log(promise)

console.log("total = ", total)
console.timeEnd('sleep2')

*/


console.time('sleep2')

var i = 0, j = 0, total = 0;
var promise = Promise.resolve('第一个')
	
var promiseList = []
while(j++ < 3) {	
	promise  = promise.then((v) => {
		total += i * 200
		console.log(`i = ${i},  v = ${v}`);
		return i < 10 ? sleep(++i * 800) : i
	})
	promiseList.push(promise)
}


console.log(promise)
console.log(promiseList)
console.log("total = ", total)
console.timeEnd('sleep2')
console.log('sdfsdf')



/*

(async () => {
	console.time('sleep2')
	var total = 0 ;
	for (var i = 0; i < 10; i++) {
		let ret = await sleep(i * 200)
		// console.log('ret = ', ret)
		total += i * 200
		console.log(i)
	}
	console.log("total = ", total)

	console.timeEnd('sleep2')
})();


*/

